package com.sfc.sdsr.server.commands;

import com.sfc.sdsr.common.model.News;
import com.sfc.sdsr.server.ClientData;
import com.sfc.sdsr.server.dao.DaoFactory;

public class CreateNews extends Command {

	private News newNews;
	
	public CreateNews(ClientData clientData) {
		dao = DaoFactory.getDao();
		if (clientData.getOperationParameter() instanceof News) {
			newNews = (News) clientData.getOperationParameter();
		} else {
			log.error("Can't create news. Client Data corrupted, no News found to Create");
			shouldExecute = false;
			returnObject = null;
		}
	}

	@Override
	public void execute() {
		log.info("Creating news");
		returnObject = dao.createNews(newNews);
	}

}
